package com.mkvld.appietijdenv2;

import com.mkvld.appietijdenv2.R;
import com.mkvld.appietijdenv2.activities.ActMainV9;
import com.mkvld.appietijdenv2.databases.ShiftDatabase;
import com.mkvld.appietijdenv2.fragments.FragInfoV9;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class ActMainTablet extends ActMainV9 {
	FragPeriodTablet fragPeriod;
	@Override
	public void onCreate(Bundle savedState) {
		super.onCreate(savedState);
		ShiftDatabase.db = new ShiftDatabase(this);
		fragPeriod = new FragPeriodTablet();
		getSupportFragmentManager().beginTransaction()
			.replace(android.R.id.content, fragPeriod)
			.commit();
	}

	@Override
	public void update() {
		super.update();
		fragPeriod.update();
	}

	@Override
	protected boolean shouldInit() {
		return true;
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.tablet_options, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.tom_settings) {
			Intent i = new Intent(getApplicationContext(), ActBlankV14.class);
			i.putExtra("frag", ActBlankV14.FRAG_SETTINGS);
			startActivityForResult(i, 0);
			return true;
		} else if (item.getItemId() == R.id.tom_breaks) {
			FragBreaksV14 breaksDial = new FragBreaksV14();
			breaksDial.show(getFragmentManager(), "");
			return true;
		} else if (item.getItemId() == R.id.tom_info) {
			FragInfoV9 infoDial = new FragInfoV9();
			infoDial.show(getSupportFragmentManager(), "");
		}
		return super.onOptionsItemSelected(item);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 0)
			update();
	}
}
